package model;

import java.util.ArrayList;

import communication.Alarm;
import communication.AlarmListener;
import communication.AlarmSender;

/**
 * Sensor class
 * @author Adrien Ledeul
 * @version 0.1
 */
public class Sensor implements AlarmSender
{
	protected ArrayList<AlarmListener> alarmListeners;

	/**
	 * Constructors
	 * 
	 */
	public Sensor() 
	{
		this.alarmListeners = new ArrayList<AlarmListener>();
	}
	
	/**
	 * Add a listener to the list
	 * @param al Alarm listener
	 */
	@Override
	public void addListener(AlarmListener al) 
	{
		this.alarmListeners.add(al);
	}
	
	/**
	 * Remove a listener from the list
	 * @param al Alarm listener
	 */
	@Override
	public void removelistener(AlarmListener al) 
	{
		this.alarmListeners.remove(al);
	}

	/**
	 * Send an alarm to listeners
	 * @param alarm Alarm
	 */
	@Override
	public void notifyListeners(Alarm alarm)
	{
		for(AlarmListener al : alarmListeners)
		{
			al.receiveAlarm(alarm);
		}
	}
}
